package com.tongguan.paypos.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.tongguan.paypos.R;
import com.tongguan.paypos.activity.MainActivity;
import com.tongguan.paypos.activity.trans.MoneyInputActivity;
import com.tongguan.paypos.base.BaseFragment;
import com.tongguan.paypos.common.AppConstants;
import com.tongguan.paypos.entity.TransUnionInfo;
import com.tongguan.paypos.utils.AppUtils;
import com.tongguan.paypos.utils.Arith;
import com.tongguan.paypos.utils.L;
import com.tongguan.paypos.utils.NumberUtils;
import com.tongguan.paypos.utils.ToastUtils;
import com.tongguan.paypos.utils.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Joylive on 2016/12/16 .
 */

public class RevokeUnionPayFragment extends BaseFragment {
    private static final int REQUEST_CODE_POS = 12000;

    @BindView(R.id.et_input_info_input)
    EditText mEtInputInfoInput;
    @BindView(R.id.btn_revoke)
    Button mBtnRevoke;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_revoke_union_pay, container, false);
        ButterKnife.bind(this, rootView);
        setTitle("刷卡撤销");
        initEvent();
        return rootView;
    }

    private void initEvent() {
        mBtnRevoke.setOnClickListener(v -> {
            String voucher = mEtInputInfoInput.getText().toString();
            if (TextUtils.isEmpty(voucher)) {
                ToastUtils.showCustom(frmCtx, "输入内容为空");
                return;
            }
            if (voucher.length() < 6) {
                ToastUtils.showCustom(frmCtx, "输入内容长度不正确");
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putString("transName", "消费撤销");
            bundle.putString("oldTrace", voucher);
            AppUtils.runComponent(frmCtx, RevokeUnionPayFragment.this, AppConstants.UNION_PAY_APP_PACKAGE, AppConstants.VOID_DIR, bundle, REQUEST_CODE_POS);
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        L.d("requestCode = " + requestCode + " resultCode = " + resultCode);
        //银联
        if (requestCode == REQUEST_CODE_POS) {
            if (resultCode == Activity.RESULT_OK) {
                String result = data.getStringExtra("result");
                String message = Utils.assembleTransUnionInfo(result, true);
                L.d(message);
                frmCtx.finish();
            } else {
                ToastUtils.showCustom(frmCtx, "失败");
            }
        }
    }
}
